﻿@model Epi.Web.MVC.Models.LinkInfoModel

@{
    ViewBag.Title = "Index.Mobile";
    Layout = "~/Views/Shared/_Layout.Mobile.cshtml";
}

<script>
    var allVals = [];

    $(document).ready(function () {

        Cancel();
    });


    function AddLinks() {


        //$('#Existingrecordstable :checked').each(function () {
        //    allVals.push($(this).val());
        //});

        Link(allVals);
    }
    function AddLinkInfo() {
        $('#Existingrecordstable :checked').each(function () {
            allVals.push($(this).val());
        });

        $("#RecordList").hide();

        // $("#LinkInfo").show();

        $("#LinkInfo").attr("style", "display: block")
    }
    function Cancel() {
        $("#RecordList").show();

        //$("#LinkInfo").hide();
        $("#LinkInfo").attr("style", "display: none")
        clearLinkInfo();

    }
    function clearLinkInfo() {
        $("#type1").attr('checked', false);
        $("#type2").attr('checked', false);
        $("#type3").attr('checked', false);
        $("#type4").attr('checked', false);
        $("#tentativerelation").attr('checked', false);
        $("#relationtosource").val("");
        $("#contactdateestimate").attr('checked', false);
        $("#contactdate").val("");
        $("#ui-datepicker-div").hide();
    }

    function Link() {


        var Date_Of_Last_Contact = $("#contactdate").val();
        var Relation_To_Source = $("#relationtosource").val();

        if ($('#contactdateestimate').is(":checked")) {
            var Date_Is_Estimated = true;
        }
        else {
            var Date_Is_Estimated = false;
        }
        if ($('#type1').is(":checked")) {
            var Contact_Type_Opt1 = true;
        }
        else {
            var Contact_Type_Opt1 = false;
        }
        if ($('#type2').is(":checked")) {
            var Contact_Type_Opt2 = true;
        }
        else {
            var Contact_Type_Opt2 = false;
        }
        if ($('#type3').is(":checked")) {
            var Contact_Type_Opt3 = true;
        }
        else {
            var Contact_Type_Opt3 = false;
        }
        if ($('#type4').is(":checked")) {
            var Contact_Type_Opt4 = true;
        }
        else {
            var Contact_Type_Opt4 = false;
        }
        if ($('#tentativerelation').is(":checked")) {
            var Tentative_Relation = true;
        }
        else {
            var Tentative_Relation = false;
        }




        $.ajax({
            url: '@Url.Action("Link", "LinkInfo")' + '?FromResponseId=' + '@Model.RecordFromId',
            type: 'POST',
            cache: false,
            traditional: true,
            data: JSON.stringify({ ToResponseId: "@Model.RecordToId.ToString()", DateOfLastContact: Date_Of_Last_Contact, DateIsEstimated: Date_Is_Estimated, ContactTypeOpt1: Contact_Type_Opt1, ContactTypeOpt2: Contact_Type_Opt2, ContactTypeOpt3: Contact_Type_Opt3, ContactTypeOpt4: Contact_Type_Opt4, TentativeRelationship: Tentative_Relation, RelationToCase: Relation_To_Source,IsNewLink : '@Model.IsNewLink' }),
            contentType: 'application/json; charset=utf-8',
            success: successFunc,
            error: errorFunc
        });
        
        function successFunc(data, status) {
            var Url ="";
            if('@Model.IsNewLink')
                  {
                Url = '@Url.Action("Index", "FormResponse")' + '/' + '@Session["ToFormId"]' + '/?PageNumber=1&ViewId=' + '@Model.ViewId' + '&ShowLinksButton=' +'@Model.RecordFromId';
                  }
               else{
                     Url = '@Url.Action("Index", "FormResponse")'+'/' + '@Session["ToFormId"]' + '/?PageNumber=1&ViewId=0&ShowExistingLinks=True';
    
                   }
            window.location.href = Url
           
        }
        function errorFunc() {
            alert('error');
        }


    }
    function EnableButton() {
        $('#AddLinkInfo').removeAttr('disabled');

    }


</script>

<style>
    div.ui-datebox-controls .ui-btn-up-a, div.ui-datebox-controls .ui-btn-up-b, div.ui-datebox-controls .ui-btn-hover-a, div.ui-datebox-controls .ui-btn-hover-b, div.ui-datebox-controls .ui-btn-active-a, div.ui-datebox-controls .ui-btn-active-b  {
    border: 1px solid #2A77BB;
    background: #2A77BB;
    color: #fff !important;
    text-shadow: none !important;
    border-radius:2px;
     box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
     margin: 0.5em 0.1em;
}


div.ui-datebox-controls .ui-body-a {
    border: 1px solid #2A77BB;
}

div.ui-datebox-controls .ui-icon {
box-shadow: none !important;
background-color: rgba(0, 0, 0, 0) !important;
}

div.ui-datebox-controls .ui-btn-inner {
    padding: 0px 0px 40px 0px !important;
    text-shadow: none !important;
}
div.ui-datebox-controls a span.ui-btn-inner {
    padding: 5px !important;
    text-shadow: none !important;
}
</style>


<div id="content" class="LinkInfodialogmobile" style="margin: 10px 10px 200px;">
    @Html.ActionLink("Return", "Index", "FormResponse", new { formid = Session["ToFormId"], Pagenumber = 1, ViewId = Model.ViewId, ShowLinksButton = Session["FromResponseId"] }, new { @class = "backlink" })
    <div id="formtitle" class="formtitle" style="display:block;">
    <h2 class="surveyTitle" style="line-height: 120%;">
        Relationship Information
    </h2>
    @*<p><span style="font-size:11pt; font-weight: bold; font-variant:small-caps;">Chosen Case:</span> <span style="font-size:11pt; font-weight: bold;">Last Name, OtherName</span> &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size:11pt; font-weight: bold; font-variant:small-caps;"> Age:</span><span style="font-size:11pt; font-weight: bold;">23</span></p>*@
</div>
<div style="clear: both;"></div>
<input type="checkbox" style="display:none; visibility:collapse;" />
<form>
    <div>
            <label for="contactdate" style="font-weight:bold;">Date of last contact:</label>
            <input id='contactdate' name='contactdate' type='date' data-role='datebox' data-options='mode:datebox,pickPageButtonTheme:e,pickPageFlipButtonTheme:e,pickPageTheme:e,useNewStyle:true' value=''>
        @*<input id="contactdate" name="contactdate" onclick="ShowDatePicker();" value="" type="text" style="width: 150px;">*@

    </div>
    <div style="margin-top:5px;">

            <label class="checkbox-label" for="contactdateestimate"><input id="contactdateestimate" type="checkbox" data-role="none" /> Contact date is estimated</label>
    </div>
    <div style="margin-top:15px;">
            <label for="relationtosource" style="font-weight:bold;">Relationship of source case to case:</label>
            <input id="relationtosource" type="text" />
    </div>
    <div style="margin-top:5px;">

            <label class="checkbox-label" for="tentativerelation"><input id="tentativerelation" type="checkbox" data-role="none" /> Tentative relationship</label>
    </div>
    <div style="margin-top:15px;">
            <label style="font-weight:bold;">Contact type (select all that apply:)</label>

            <label class="checkbox-label" for="type1"><input id="type1" type="checkbox" data-role="none" /> 1 - Touched the body fluids of the case (blood, vomit, saliva, urine, feces)</label>

            <label class="checkbox-label" for="type2"><input id="type2" type="checkbox" data-role="none" /> 2 - had direct physical contact with the body of the case (alive or dead)</label>

            <label class="checkbox-label" for="type3"><input id="type3" type="checkbox" data-role="none" /> 3 - Touched or shared the linens, clothes, or dishes/utensils of the case</label>

            <label class="checkbox-label" for="type4"><input id="type4" type="checkbox" data-role="none" /> 4 - Slept, ate or spent time in the same household or room as the case</label>
    </div>
     
        
            <div id="exitbtns" style="margin-top:25px;">
                <a onclick="Link();" class='login'>Save</a>
                @if(!@Model.IsNewLink)
                {
                @Html.ActionLink("Cancel", "Index", "FormResponse", new { formid = Session["ToFormId"], Pagenumber = 1, ViewId = 0, ShowExistingLinks = true }, new { @class = "login" })
                }
                   

            </div>
                                       
</form>
</div>
